<template>
  <div class="container">
    <vue-particles id="particles" :options="particlesOptions" />

    <div class="content">
      <h1 class="title">
        <span v-if="window.location.href.includes('f2es.cn')">宝贝上班辛苦了，{{ nameList[nameIndex].name }}提醒您</span> 距离下班还剩
      </h1>
      <div class="countdown">
        <div class="time-block">
          <div class="number">{{ hours }}</div>
          <div class="label">小时</div>
        </div>
        <div class="colon">:</div>
        <div class="time-block">
          <div class="number">{{ minutes }}</div>
          <div class="label">分钟</div>
        </div>
        <div class="colon">:</div>
        <div class="time-block">
          <div class="number">{{ seconds }}</div>
          <div class="label">秒</div>
        </div>
      </div>
      <div class="progress">
        <div class="progress-bar" :style="progressStyle"></div>
      </div>
      <div class="motd">{{ currentQuote }}</div>
      <div>
        <video v-if="nameIndex === 1" :src="nameList[nameIndex].pic" autoplay loop muted style="max-height: 300px"></video>
        <img v-else :src="nameList[nameIndex].pic" alt="" style="max-height: 300px" />
      </div>

      <div v-if="window.location.href.includes('f2es.cn')">
        <div v-if="nameList[nameIndex].name === '栗子姐姐的彭于晏'">
          <img src="../../assets/1.jpg" alt="" style="max-height: 300px" />
        </div>
        <div v-else-if="nameList[nameIndex].name === '王子如'">
          <img src="../../assets/2.gif" alt="" style="max-height: 300px" />
        </div>
        <div v-else-if="nameList[nameIndex].name === '代森'">
          <img src="../../assets/3.jpg" alt="" style="max-height: 300px" />
        </div>
        <div v-else-if="nameList[nameIndex].name === '沈壮志'">
          <video src="../../assets/1.mp4" autoplay loop muted style="max-height: 300px"></video>
        </div>
        <div v-else-if="nameList[nameIndex].name === '杭州麻将'">
          <img src="../../assets/5.jpg" alt="" style="max-height: 300px" />
        </div>
      </div>
    </div>
  </div>
</template>

<script>
import VueParticles from 'vue-particles';

export default {
  components: {
    VueParticles,
  },
  data() {
    return {
      window: window,
      nameList: [
        { name: '王子如', pic: '../../assets/2.gif' },
        { name: '沈壮志', pic: '../../assets/1.mp4' },
        { name: '代森', pic: '../../assets/3.jpg' },
        { name: '栗子姐姐的彭于晏', pic: '../../assets/1.jpg' },
        { name: '杭州麻将', pic: '../../assets/5.jpg' },
      ],
      now: Date.now(),
      quotes: [
        '🌻 今天的努力是明天的底气，坚持就是胜利！',
        '🚀 每个不曾起舞的日子，都是对生命的辜负～',
        '✨ 完成工作不是结束，而是新可能的开始',
        '⏳ 时间像海绵里的水，挤挤总会有的',
        '🌱 进步是一点一滴积累起来的',
        '🎯 你专注工作的样子，就是最美的风景',
        '🌈 休息是为了走更长远的路',
        '💡 灵感来自持续的行动',
      ],
      currentQuote: '',
      particlesOptions: {
        particles: {
          number: { value: 80 },
          color: { value: '#ffffff' },
          shape: { type: 'circle' },
          opacity: { value: 0.5 },
          size: { value: 3 },
          move: {
            enable: true,
            speed: 1,
            direction: 'none',
            random: false,
            straight: false,
            out_mode: 'out',
            bounce: false,
          },
        },
        interactivity: {
          events: {
            onhover: { enable: true, mode: 'repulse' },
          },
        },
      },
    };
  },
  computed: {
    targetTime() {
      const now = new Date();
      const isTuesdayOrThursday = [2, 4].includes(now.getDay()); // 0=周日
      let target = new Date(now);

      // 设置基准时间
      if (isTuesdayOrThursday) {
        target.setHours(20, 30, 0, 0); // 周二四20:30
      } else {
        target.setHours(18, 0, 0, 0); // 其他工作日18:00
      }

      // 处理跨天
      if (now > target) {
        target.setDate(target.getDate() + 1);

        // 重新判断新日期的下班时间
        const newDay = target.getDay();
        if ([2, 4].includes(newDay)) {
          target.setHours(20, 30, 0, 0);
        } else {
          target.setHours(18, 0, 0, 0);
        }
      }
      return target;
    },
    diff() {
      return Math.max(this.targetTime - this.now, 0);
    },
    hours() {
      return Math.floor(this.diff / 1000 / 60 / 60)
        .toString()
        .padStart(2, '0');
    },
    minutes() {
      return Math.floor((this.diff / 1000 / 60) % 60)
        .toString()
        .padStart(2, '0');
    },
    seconds() {
      return Math.floor((this.diff / 1000) % 60)
        .toString()
        .padStart(2, '0');
    },
    progressStyle() {
      const isSpecialDay = [2, 4].includes(this.targetTime.getDay());
      const totalHours = isSpecialDay ? 10.5 : 9; // 工作时间基准
      const totalTime = totalHours * 60 * 60 * 1000;
      const passed = totalTime - this.diff;
      const width = Math.min(((passed / totalTime) * 100).toFixed(2), 100);
      return {
        width: `${width}%`,
        background: `linear-gradient(90deg, #ff6b6b ${width}%, #4ecdc4 ${width}%)`,
      };
    },
    nameIndex() {
      return Math.floor(Math.random() * this.nameList.length);
    },
  },
  mounted() {
    this.updateQuote();
    setInterval(() => {
      this.now = Date.now();
      // 每小时更换一次语录
      if (new Date().getMinutes() === 0) {
        this.updateQuote();
      }
    }, 1000);
  },
  methods: {
    updateQuote() {
      const now = new Date();
      const isWeekend = [0, 6].includes(now.getDay());
      const isWorkTime = !isWeekend && (now.getHours() < 18 || ([2, 4].includes(now.getDay()) && now.getHours() < 20));

      if (isWeekend) {
        this.currentQuote = '🎉 周末愉快！好好享受自由时光～';
      } else if (isWorkTime) {
        const randomIndex = Math.floor(Math.random() * this.quotes.length);
        this.currentQuote = this.quotes[randomIndex];
      } else {
        this.currentQuote = '🏖️ 下班时间到！享受属于自己的美好时光吧～';
      }
    },
  },
};
</script>

<style scoped>
.container {
  height: 100vh;
  background: linear-gradient(45deg, #1a1a1a, #2d3436);
  position: relative;
  overflow: hidden;
}

#particles {
  position: absolute;
  width: 100%;
  height: 100%;
}

.content {
  position: relative;
  z-index: 1;
  display: flex;
  flex-direction: column;
  align-items: center;
  justify-content: center;
  height: 100%;
  color: white;
  text-align: center;
  padding: 20px;
}

.title {
  font-size: 2.5rem;
  margin-bottom: 1.5rem;
  text-shadow: 0 0 10px rgba(255, 255, 255, 0.5);
  animation: glow 2s ease-in-out infinite alternate;
}

.countdown {
  display: flex;
  gap: 1.5rem;
  align-items: center;
  flex-wrap: wrap;
  justify-content: center;
}

.time-block {
  background: rgba(255, 255, 255, 0.1);
  padding: 1rem 2rem;
  border-radius: 15px;
  backdrop-filter: blur(5px);
  box-shadow: 0 0 20px rgba(78, 205, 196, 0.3);
  transition: transform 0.3s ease;
  min-width: 120px;
}

.time-block:hover {
  transform: translateY(-10px);
}

.number {
  font-size: 3.5rem;
  font-weight: bold;
  background: linear-gradient(45deg, #ff6b6b, #4ecdc4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  line-height: 1;
}

.label {
  font-size: 1rem;
  color: rgba(255, 255, 255, 0.8);
  margin-top: 0.5rem;
}

.colon {
  font-size: 2.5rem;
  margin-bottom: 1rem;
  animation: pulse 1s infinite;
}

.progress {
  width: 100%;
  max-width: 600px;
  height: 8px;
  background: rgba(255, 255, 255, 0.1);
  border-radius: 4px;
  margin: 2rem 0;
  overflow: hidden;
}

.progress-bar {
  height: 100%;
  border-radius: 4px;
  transition: all 1s linear;
}

.motd {
  margin-top: 1.5rem;
  font-size: 1.2rem;
  color: #fff;
  opacity: 0.9;
  max-width: 90%;
  text-align: center;
  animation: float 6s ease-in-out infinite;
  background: linear-gradient(90deg, #ff6b6b, #4ecdc4);
  -webkit-background-clip: text;
  -webkit-text-fill-color: transparent;
  padding: 0 15px;
}

@keyframes glow {
  from {
    text-shadow: 0 0 10px #fff;
  }
  to {
    text-shadow: 0 0 20px #fff, 0 0 30px #4ecdc4;
  }
}

@keyframes pulse {
  0% {
    opacity: 1;
  }
  50% {
    opacity: 0.3;
  }
  100% {
    opacity: 1;
  }
}

@keyframes float {
  0%,
  100% {
    transform: translateY(0);
  }
  50% {
    transform: translateY(-8px);
  }
}

@media (max-width: 768px) {
  .title {
    font-size: 2rem;
  }
  .number {
    font-size: 2.5rem;
  }
  .time-block {
    padding: 0.8rem 1.5rem;
    min-width: 100px;
  }
  .motd {
    font-size: 1rem;
  }
}
</style>
